﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.Combat;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

namespace ArmsCC
{
    class ArmsCC : CombatRoutine
    {
        public override sealed string Name { get { return "ArmsCC v" + mVersion; } }
        public override WoWClass Class { get { return WoWClass.Warrior; } }

        private static Version mVersion = new Version(0, 1);
        private static Helpers mHelpers = new Helpers();
        private static Spells mSpells = new Spells();

        private UInt64 i = 0;

        private static LocalPlayer Me { get { return ObjectManager.Me; } }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Pulse()
        {
            base.Pulse();
        }

        public override void Combat()
        {
            using (new FrameLock())
            {
                int curRage = (int) Me.CurrentRage;

                double msCooldown = mHelpers.GetSpellCooldown("Mortal Strike");
                double csCooldown = mHelpers.GetSpellCooldown("Colossus Smash");

                bool gcdWatch = msCooldown >= 1.5 && csCooldown >= 1.5;

                if (mHelpers.CanCast("Heroic Strike") && curRage >= 70)
                {
                    mHelpers.Cast("Heroic Strike");
                }

                if (mHelpers.IsAuraActive(Me.CurrentTarget, "Rend", Me.Guid) && (!mHelpers.IsAuraActive(Me, mSpells.TASTE_FOR_BLOOD) || msCooldown < 1.5 || csCooldown < 1.5))
                {
                    if (mHelpers.CanCast("Berserker Stance") && !Me.HasAura("Berserker Stance"))
                    {
                        mHelpers.Cast("Berserker Stance");
                    }
                }
                else if (mHelpers.CanCast("Battle Stance") && !Me.HasAura("Battle Stance") && gcdWatch)
                {
                    mHelpers.Cast("Battle Stance");
                }

                if (mHelpers.CanCast("Rend") && !mHelpers.IsAuraActive(Me.CurrentTarget, "Rend", Me.Guid))
                {
                    mHelpers.Cast("Rend");
                    return;
                }

                if (Me.CurrentTarget.HealthPercent >= 20)
                {
                    if (mHelpers.CanCast("Colossus Smash") && !mHelpers.IsAuraActive(Me.CurrentTarget, "Colossus Smash", Me.Guid))
                    {
                        mHelpers.Cast("Colossus Smash");
                    }

                    else if (mHelpers.CanCast("Mortal Strike"))
                    {
                        mHelpers.Cast("Mortal Strike");
                    }

                    else if (mHelpers.IsAuraActive(Me, mSpells.TASTE_FOR_BLOOD) && gcdWatch)
                    {
                        mHelpers.Cast("Overpower");
                    }

                    else if (mHelpers.CanCast("Slam") && curRage >= 35 && gcdWatch)
                    {
                        mHelpers.Cast("Slam");
                    }
                }
            }
        }
    }
}
